package cn.easyshipping.cloud.business.feign;

import cn.easyshipping.cloud.common.constant.ErrorCode;
import cn.easyshipping.cloud.common.util.ResponseUtil;
import cn.easyshipping.cloud.business.entity.BPort;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author sunyongqiang
 */
@FeignClient(name = "ryd-service-provider", fallback = BPortFeignClientFallback.class)
public interface BPortFeignClient {
    @GetMapping("/api/port/{id}")
    BPort findById(@PathVariable("id") String id);
    @PostMapping("/api/port/{id}")
    String updatePortName(@PathVariable String id, @RequestParam String portName);
}

@Component
class BPortFeignClientFallback implements BPortFeignClient {

    @Autowired
    private ResponseUtil responseUtil;

    @Override
    public BPort findById(String id) {
        BPort bPort = new BPort();
        bPort.setId(id);
        return bPort;
    }

    @Override
    public String updatePortName(String id, String portName) {
        return JSON.toJSONString(responseUtil.failedResult(ErrorCode.serverError));
    }
}
